home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / LGP250S1.ZIP / src / libgplus.5 / libgplus / proto-ki / makefile.new < prev    next >
Makefile  |  1991-07-30  |  13KB  |  439 lines

  1. #******************************************************************************
  2. #  This GNUmakefile is useful for large and complex projects which involve
  3. # both G++ library prototypes, and prototypes added by the user(s).  It 
  4. # is assumed that certain conventions are followed.
  5. #
  6. # 1) each object has its own source and header files.  For example class W 
  7. #    would have W.h and W.cc
  8. #
  9. # 2) each prototype object has its own source and header files (W.hP and W.ccP)
  10. #
  11. # 3) object header files are contained in directory $(IDIR) (for Include
  12. #    DIRectory)
  13. #
  14. # 4) object source files are contained in the current directory
  15. #
  16. # 5) prototype instantiations are contained in $(PC) (for Prototype C++
  17. #    directory)
  18. #
  19. # 6) user prototype files (both header and source) are contained in $(IPP)
  20. #
  21. # 7) non-class code is contained in .h and .cc files, which live in $(IDIR)
  22. #    and the current directory respectively
  23. #
  24. # *) as an extra, I have added the convention that whenever a W.cc file
  25. #    is being compiled, the macro _W_cc is defined.  This is useful
  26. #    particularly for conditional parts of header files (for example,
  27. #    W.h could have ifdef _W_cc ...
  28. #
  29. # The makefile works in the following manner: the source dependencies are
  30. # contained in .Makefile.S_DEP, while the (machine generated) object 
  31. # dependencies are contained in .Makefile.O_DEP.  The types needed by
  32. # the program are defined by several variables, and the makefile generates
  33. # the necessary dependencies (both source and object) from those variables.
  34. # The prototype lists are contained in .Makefile.TYPES.
  35. # NOTE: in order to create the machine generated files .Makefile.TYPES,
  36. #  .Makefile.S_DEP, and .Makefile.O_DEP, empty versions of these
  37. #  file must exist.  They can be easily created using "touch <file>".
  38. #
  39. #  -- Carl Staelin
  40. #     staelin@princeton.edu
  41. #******************************************************************************
  42.  
  43. #******************************************************************************
  44. # standard Makefile definitions
  45.  
  46. comma := ,
  47. space := $(empty) $(empty)
  48. tab := $(empty)    $(empty)
  49.  
  50. #******************************************************************************
  51. # definitions from environment variables
  52.  
  53. # the CPATH include directories 
  54. cpath-include-directories := $(addprefix -I, $(subst :,$(space),$(CPATH)))
  55.  
  56. # the LPATH load directories 
  57. lpath-load-directories := $(addprefix -L, $(subst :,$(space),$(LPATH)))
  58.  
  59. #******************************************************************************
  60. # Basic definitions
  61.  
  62. HOST := $(shell hostname)
  63.  
  64. BASE := 
  65.  
  66. # CMU Directories
  67. USR  := $(BASE)/usr
  68. MACH := $(BASE)/usr/mach
  69. CS   := $(BASE)/usr/cs
  70.  
  71. # GNU directories
  72. GNULIBDIR := $(BASE)/usr/local/lib
  73. GNUIDIR := $(GNULIBDIR)/g++-include
  74.  
  75. # the g++ library prototypes...
  76. LPP := $(GNUIDIR)
  77. PC := ../libg++
  78.  
  79. # the user's library prototypes...
  80. IPP := ../proto
  81.  
  82. # the include directory
  83. IDIR := ../include
  84.  
  85. # the include directories needed...
  86. IDIRS := -I$(IDIR) -I$(PC) -I$(GNUIDIR) $(cpath-include-directories) 
  87.  
  88. # the directories where the libraries live...
  89. LDIRS := $(lpath-load-directories)
  90.  
  91. #******************************************************************************
  92. # standard function (and associated variables) definitions
  93.  
  94. C++ = g++
  95. C++FLAGS = -pipe -O $(IDIRS) 
  96.         -Dc_plusplus \
  97.         -DDEBUG \
  98.         -D$(strip $(subst .,_, _$(basename $(@F))_cc)) 
  99.  
  100.  
  101. GENCLASS = ../bin/genclass.extnsn
  102. PREPEND  = ../bin/prepend
  103. HIERARCHY    = ../bin/hierarchy
  104. MAKE_TYPES    = ../bin/make-types
  105. PROTOTYPE    = ../bin/prototype
  106.  
  107. #******************************************************************************
  108. # implicit rules
  109.  
  110. %.o : %.cc
  111.     $(C++)    $(C++FLAGS) \
  112.         -c -o $@ $(@D)$(basename $(@F)).cc
  113.  
  114. #******************************************************************************
  115. # User types
  116.  
  117. BASIC_TYPES = \
  118.     int \
  119.     u_int \
  120.     l_int \
  121.     l_u_int 
  122.  
  123. # generated by this make file (initially create an empty .Makefile.TYPES
  124. # so that "make dependencies" can create the real file)
  125. include .Makefile.TYPES
  126.  
  127. #******************************************************************************
  128. # User types (with sample values filled in) 
  129. # NOTE: do NOT add .h to the end of these, MAKE does it for you!
  130.  
  131. HEADER_FILES = \
  132.     disk_set \
  133.     file_types \
  134.     include \
  135.     inode \
  136.     inode_t \
  137.     lib \
  138.     main \
  139.     nfs_functions \
  140.     nfs_mount \
  141.     nfs_params \
  142.     nfs_prot \
  143.     system 
  144.  
  145. SOURCE_FILES = \
  146.     disk_set \
  147.     lib \
  148.     nfs_auxil \
  149.     nfs_dirent \
  150.     nfs_fh \
  151.     nfs_ipcress \
  152.     nfs_links \
  153.     nfs_main \
  154.     nfs_mnt_serv \
  155.     nfs_mount_xdr \
  156.     nfs_prot_xdr \
  157.     nfs_serv1 \
  158.     nfs_serv2 \
  159.     nfs_serv3 \
  160.     nfs_serv4 \
  161.  
  162. #******************************************************************************
  163. # some sample machine generated user-file stuff
  164. #
  165. ../include/file_types.h : ../include/file_types.type.h \
  166.               ../include/file_types.operation.h
  167. ../include/Substrate_file.h : ../include/file_types.includes.h
  168.  
  169. ../include/file_types.type.h : ../include/file_types.hierarchy
  170.     $(HIERARCHY) -voutput_type=type ../include/file_types.hierarchy > $@
  171.  
  172. ../include/file_types.includes.h : ../include/file_types.hierarchy
  173.     $(HIERARCHY) -voutput_type=general -vpreamble='#include "' \
  174.      -vpostamble='.h"' -vprint_first=1 ../include/file_types.hierarchy > $@
  175.  
  176. ../include/file_types.operation.h : ../include/file_types.hierarchy
  177.     (echo '#define FILE_TYPES_OPERATION(OPERATION)  \' ; \
  178.      $(HIERARCHY) -voutput_type=general -vpreamble='OPERATION(' \
  179.       -vpostamble=') \' -vprint_first=1 ../include/file_types.hierarchy ; \
  180.       echo ; ) | sed 's/\.//g' > $@ ;
  181.  
  182. #******************************************************************************
  183. # source files...
  184.  
  185. HEADERS := $(wildcard $(addprefix $(IDIR)/, $(addsuffix .h, \
  186.                                           $(USER_TYPES) $(HEADER_FILES))))
  187.  
  188. SOURCES := $(wildcard $(addsuffix .cc, $(USER_TYPES) $(SOURCE_FILES)))
  189.  
  190. OBJECTS := $(patsubst %.cc,%.o,$(SOURCES))
  191.  
  192. #******************************************************************************
  193. # User prototype instantiations
  194.  
  195. USER_PROTO_HEADERS := \
  196.     $(addprefix $(PC)/,     \
  197.       $(addsuffix .h,       \
  198.         $(foreach type,     \
  199.           $(basename        \
  200.             $(notdir        \
  201.               $(wildcard     \
  202.             $(addprefix $(IPP)/,                     \
  203.                         $(addsuffix .hP,                \
  204.                             $(USER_BASE_PROTO_TYPES)))))),  \
  205.           $(filter %.$(type), $(USER_PROTO_TYPES)))))
  206.  
  207. USER_PROTO_SOURCES := \
  208.     $(addprefix $(PC)/,         \
  209.       $(addsuffix .cc,        \
  210.         $(foreach type,        \
  211.           $(basename         \
  212.             $(notdir        \
  213.           $(wildcard         \
  214.             $(addprefix $(IPP)/,\
  215.                     $(addsuffix .ccP,        \
  216.                   $(USER_BASE_PROTO_TYPES)))))),\
  217.            $(filter %.$(type), $(USER_PROTO_TYPES)))))
  218.  
  219. USER_PROTO_OBJECTS := $(patsubst %.cc, %.o, $(USER_PROTO_SOURCES))
  220.  
  221. USER_PROTO_TYPE_SOURCES := \
  222.     $(wildcard                    \
  223.       $(addprefix $(IPP)/,                \
  224.         $(addsuffix .hP, $(USER_BASE_PROTO_TYPES))  \
  225.         $(addsuffix .ccP, $(USER_BASE_PROTO_TYPES))))
  226.  
  227. #******************************************************************************
  228. # libg++ prototype instantiations
  229.  
  230. LIB_PROTO_HEADERS := \
  231.      $(addprefix $(PC)/,                        \
  232.        $(addsuffix .h,                        \
  233.          $(foreach type,                        \
  234.            $(basename                        \
  235.          $(notdir                        \
  236.            $(wildcard                        \
  237.              $(addprefix $(LPP)/,                \
  238.                $(addsuffix .hP, $(LIB_BASE_PROTO_TYPES)))))),    \
  239.            $(filter %.$(type), $(LIB_PROTO_TYPES)))))
  240.  
  241. LIB_PROTO_SOURCES := \
  242.     $(addprefix $(PC)/,                         \
  243.       $(addsuffix .cc,                        \
  244.         $(foreach type,                        \
  245.           $(basename                        \
  246.             $(notdir                        \
  247.           $(wildcard                        \
  248.             $(addprefix $(LPP)/,                \
  249.               $(addsuffix .ccP, $(LIB_BASE_PROTO_TYPES)))))),
  250.           $(filter %.$(type), $(LIB_PROTO_TYPES)))))
  251.  
  252. LIB_PROTO_OBJECTS := $(patsubst %.cc, %.o, $(LIB_PROTO_SOURCES))
  253.  
  254. .PHONY : test
  255. test :
  256.     @echo LIB_PROTO_TYPES = "${LIB_PROTO_TYPES}";
  257.     @echo LIB_BASE_PROTO_TYPES = "${LIB_BASE_PROTO_TYPES}" ;
  258.     @echo LIB_PROTO_OBJECTS = "${LIB_PROTO_OBJECTS}" ;
  259.     @echo LIB_PROTO_HEADERS = "${LIB_PROTO_HEADERS}" ;
  260.  
  261. #*****************************************************************************
  262. # main procedures..
  263.  
  264. # example:
  265. foo : foo.o $(OBJECTS) 
  266.     $(C++) $(C++FLAGS) -o $@ foo.o $(OBJECTS) $(LDIRS)
  267.  
  268. sources : $(SOURCES) 
  269.  
  270. #******************************************************************************
  271. # various cleanup stuff...
  272.  
  273. .PHONY : rmback clean realclean
  274.  
  275. rmback : 
  276.     cd .. ; rm -f proto/*~ include/*~ src/*~
  277.  
  278. clean : rmback
  279.     rm -f $(OBJECTS) $(PROTOLIB) $(LIB_PROTO_OBJECTS) $(USER_PROTO_OBJECTS)
  280.  
  281. realclean : clean
  282.     rm -f $(LIB_PROTO_SOURCES) $(USER_PROTO_SOURCES) $(LIB_PROTO_HEADERS) \
  283.           $(USER_PROTO_HEADERS)
  284.  
  285.  
  286. #*****************************************************************************
  287. # debugging actions
  288.  
  289. %.E : %.cc
  290.     $(C++) $(C++FLAGS) -E $(@D)$(basename $(@F)).cc > $@
  291.  
  292. %.s : %.cc
  293.     $(C++) -S $(C++FLAGS) $< -o $@
  294.  
  295. #******************************************************************************
  296. # "functions" for creating library source code from prototypes
  297.  
  298. parameters = $(subst .,$(space),$(notdir $(basename $(basename $@))))
  299. ifdef_filename = $(subst .,_,$(notdir $(basename $@)))
  300.  
  301. generic-type = $(subst .,,$(suffix $(basename $(notdir $@))))
  302.  
  303. #
  304. # return the type if it should be a "val" type (pointer or basic type)
  305. #
  306. parameter-val-q = $(filter %_p, $(parameter)) $(filter-out %_p, $(filter $(parameter), $(BASIC_TYPES)))
  307.  
  308. #
  309. # return the list of pairs of types and their prototype type (val or ref)
  310. #
  311. proto-type-arg = $(parameter) \
  312.     $(patsubst %, val, $(filter 1, $(words $(parameter-val-q)))) \
  313.     $(patsubst %, ref, $(filter-out 1, $(words $(parameter-val-q))))
  314.  
  315. define make-proto-file
  316. $(GENCLASS) \
  317.   $(dir $<) \
  318.   $(dir $@) \
  319.   $(suffix $@) \
  320.   $(foreach parameter, $(parameters), $(proto-type-arg)) \
  321.   $(generic-type) ;
  322. endef
  323.  
  324.  
  325. define prepend-proto-includes
  326. $(PREPEND) \
  327.   $(addsuffix .h, $(basename $@)) \
  328.   '#include "include.h"' \
  329.   $(patsubst %, '#include "%.h"',                \
  330.     $(foreach type, $(USER_TYPES)                \
  331.             $(USER_PROTO_TYPES)                \
  332.             $(LIB_PROTO_TYPES),                \
  333.             $(patsubst %, $(type),            \
  334.                   $(filter $(subst .,, $(type)),\
  335.                            $(patsubst %_p, %, $(parameters)))))) ;
  336. endef
  337.  
  338. #******************************************************************************
  339. # libg++ prototype dependencies
  340.  
  341.  
  342. #
  343. # Used to automatically generate a %_p.defs file, which is required by classes
  344. # which do comparisons, for pointer types to objects which have the real 
  345. # comparison code.
  346. #
  347. # this will cat the appropriate strings 
  348. #
  349. $(addprefix $(PC)/,    \
  350.   $(addsuffix .h,    \
  351.     $(filter-out char_p.defs, $(filter %_p.defs, $(LIB_PROTO_TYPES))))) : 
  352.     @ echo creating $@ ;                 \
  353.     ( ifdef_filename=$(strip $(ifdef_filename))     \
  354.       p=$(strip $(patsubst %_p, %, $(parameters)))     \
  355.       ../bin/make-defs-file ) > $@ ;
  356.  
  357. lib_proto_intermediate_sources = \
  358.     $(filter-out %_p.defs.h, $(LIB_PROTO_HEADERS) $(LIB_PROTO_SOURCES)) \
  359.     $(addprefix $(PC)/, $(addsuffix .h, char_p.defs)) 
  360.  
  361. lib_type_and_suffix_list = \
  362.     $(sort                                 \
  363.       $(join $(suffix $(basename $(lib_proto_intermediate_sources))),\
  364.          $(addprefix ., $(suffix $(lib_proto_intermediate_sources)))))
  365.  
  366. #******************************************************************************
  367. # prototype dependencies
  368.  
  369. proto_intermediate_sources = \
  370.     $(USER_PROTO_HEADERS) \
  371.     $(USER_PROTO_SOURCES) 
  372.  
  373. type_and_suffix_list = \
  374.     $(sort                                \
  375.       $(join $(suffix $(basename $(proto_intermediate_sources))),    \
  376.           $(addprefix ., $(suffix $(proto_intermediate_sources)))))
  377.  
  378. #******************************************************************************
  379. # generate machine generated dependencies 
  380.  
  381. H_FILES  = $(HEADERS) $(LIB_PROTO_HEADERS) $(USER_PROTO_HEADERS)
  382. CC_FILES = $(SOURCES) $(LIB_PROTO_SOURCES) $(USER_PROTO_SOURCES)
  383.  
  384. DEPENDENCIES = $(addsuffix .d, $(basename $(CC_FILES)))
  385.  
  386. $(addsuffix .d, $(basename $(CC_FILES))) : %.d : %.cc
  387.     ( echo -n $(@D) ; $(C++) -M $(C++FLAGS) $*.cc) > $@;
  388.  
  389. #******************************************************************************
  390. # machine generated type stuff
  391. #
  392.  
  393. $(DEPENDENCIES) : $(H_FILES)
  394.  
  395. .PHONY : dependencies source-dependencies object-dependencies 
  396.  
  397. dependencies : type-definitions source-dependencies
  398.     @ $(MAKE) object-dependencies 
  399.  
  400. object-dependencies : $(DEPENDENCIES) 
  401.     @echo making object dependencies... ; \
  402.     rm .Makefile.O_DEP ; \
  403.     ls . | grep '\.d$$' > /tmp/dependencies ; \
  404.     ls $(PC) | gawk '{printf "$(PC)/%s\n", $$0 ; }' | grep '\.d$$' >> \
  405.         /tmp/dependencies ; \
  406.     for file in `cat /tmp/dependencies` ; do \
  407.       cat $$file ; \
  408.     done > .Makefile.O_DEP.tmp ; \
  409.     mv .Makefile.O_DEP.tmp .Makefile.O_DEP ; \
  410.     for file in `cat /tmp/dependencies` ; do \
  411.       rm $$file ; \
  412.     done ; \
  413.     rm /tmp/dependencies ;
  414.  
  415.  
  416. source-dependencies : 
  417.     @ echo making source dependencies... ; \
  418.     ($(PROTOTYPE) -voutput_type=libg++-prototypes \
  419.         ../include/prototype.dependencies | \
  420.      gawk '($$1 !~ "_p.defs$$") || ($$1 == "char_p.defs") { print ; }' | \
  421.      PROTO_SOURCE=$(LPP) PP=LPP ../bin/make-source-dependencies ; \
  422.      ($(PROTOTYPE) -voutput_type=user-prototypes \
  423.         ../include/prototype.dependencies ; \
  424.       $(HIERARCHY) -voutput_type=general ../include/file_types.hierarchy)|\
  425.      PROTO_SOURCE=$(IPP) PP=IPP ../bin/make-source-dependencies ; \
  426.     ) > .Makefile.S_DEP ;
  427.  
  428. type-definitions :
  429.     @ echo make type definitions... ; \
  430.     $(MAKE_TYPES) > .Makefile.TYPES ;
  431.  
  432. #******************************************************************************
  433. # include machine generated dependencies 
  434.  
  435. include .Makefile.S_DEP
  436. include .Makefile.O_DEP
  437.